# -*- coding: utf-8 -*-
from datetime import timedelta

from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dwd.dwd_warhouse.dwd_wide_barscan_operations_hist_dt import jms_dwd__dwd_wide_barscan_operations_hist_dt
from jms.dwd.tms.dwd_tmsnew_shipment_stop_union_base_dt import jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
from jms.dwd.tms.dwd_tmsnew_shipment_union_base_dt import jms_dwd__dwd_tmsnew_shipment_union_base_dt
from utils.operators.spark_submit import SparkSubmitOperator

jms_dwd__dwd_wide_rank_basic_scaninfo_tms_incre_dt = SparkSubmitOperator(
    task_id='jms_dwd__dwd_wide_rank_basic_scaninfo_tms_incre_dt',
    pool_slots=9,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_dwd__dwd_wide_rank_basic_scaninfo_tms_incre_dt_{{ execution_date | date_add(1) | cst_ds }}',  # yarn 任务名称
    driver_memory='38G',
    executor_memory='20G',
    executor_cores=16,
    retries=0,
    num_executors=120,
    # yarn_queue='warehouse',
    conn_id='spark_warehouse',
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    conf={'spark.executor.memoryOverhead': '6G',
          'spark.core.connection.ack.wait.timeout': 3000,
          'spark.default.parallelism': 7000,
          'spark.sql.shuffle.partitions': 7000,
          'spark.dynamicAllocation.maxExecutors': 140,
          'spark.locality.wait': 60,
          'spark.network.timeout': 300,
          'spark.driver.maxResultSize': 20,
          'spark.driver.cores': 8,
          'spark.yarn.queue': 'default',
          'spark.dynamicAllocation.enabled': 'false',
          #'spark.sql.parquet.compression.codec': 'gzip',
          'spark.shuffle.service.enabled': 'true',
          # 'spark.reducer.maxBlocksInFlightPerAddress': 3,
          'spark.shuffle.io.maxRetries': 20,
          'spark.shuffle.io.retryWait': 20,
          'spark.shuffle.memoryFraction': '0.8',
          'spark.shuffle.file.buffer':'64k',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=16',
          'spark.driver.extraJavaOptions':'-XX:+UseG1GC'
          },
    java_class='com.yunlu.bigdata.jobs.udaf.YlBarscanToTracePro',  # spark 主类
    application='hdfs:///scheduler/jms/spark/dwd_warhouse/dwd_wide_rank_basic_scaninfo_tms_incre_dt/jobs-1.0-SNAPSHOT.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_ds }}', '9', '0'],
    # 参数dt 2020-10-26
    execution_timeout=timedelta(hours=2),
)

jms_dwd__dwd_wide_rank_basic_scaninfo_tms_incre_dt << [
    jms_dwd__dwd_wide_barscan_operations_hist_dt,
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt,
    jms_dwd__dwd_tmsnew_shipment_union_base_dt,
]